package edu.pitt.dbmi.odie.gapp.gwt.client.analysis.datasource;

import com.smartgwt.client.data.DSRequest;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.types.DSDataFormat;

public class ODIE_AnalysisDataSource extends DataSource {

	private static ODIE_AnalysisDataSource instance = null;

	public static ODIE_AnalysisDataSource getInstance() {
		if (instance == null) {
			instance = new ODIE_AnalysisDataSource("analysisDS");
		}
		return instance;
	}

	public ODIE_AnalysisDataSource(String id) {

		setID(id);
		
		setDataFormat(DSDataFormat.XML);
		setRecordXPath("//analysis");
		setDataURL("odie_client/snapshot?category=analysis");

		DataSourceTextField odieIdField = new DataSourceTextField("odieId",
				"odieId", 5, false);
		odieIdField.setPrimaryKey(true);
		odieIdField.setHidden(true);

		DataSourceTextField userIdField = new DataSourceTextField("userId",
				"userId", 5, false);
		userIdField.setHidden(true);

		DataSourceTextField titleField = new DataSourceTextField("title",
				"title", 45, false);

		DataSourceTextField analysisStatusField = new DataSourceTextField(
				"analysisStatus", "status", 15, false);

		DataSourceIntegerField unitsRequestedField = new DataSourceIntegerField(
				"unitsRequested", "requested", 3, false);

		DataSourceIntegerField unitsCompletedField = new DataSourceIntegerField(
				"unitsCompleted", "completed", 3, false);

		DataSourceTextField progressField = new DataSourceTextField("progress",
				"progress", 100, false);

		setFields(odieIdField, userIdField, titleField, analysisStatusField,
				unitsRequestedField, unitsCompletedField, progressField);

	}

	protected Object transformRequest(DSRequest dsRequest) {
		return super.transformRequest(dsRequest);
	}
}
